package com.beyondsoft.common.activiti.utils;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class StringUtil {
    private static final Logger log = LoggerFactory.getLogger(StringUtil.class);

    public static String byte2String(byte[] src) {
        return byte2String(src, "UTF-8");
    }

    public static String byte2String(byte[] src, String charset) {
        String res = null;

        try {
            if (src == null) {
                res = "";
            } else {
                if (StringUtils.isBlank(charset)) {
                    charset = "UTF-8";
                }

                res = new String(src, charset);
            }

            return res;
        } catch (Exception var4) {
            log.info(var4.getMessage(), var4);
            throw new RuntimeException("byte数组转String异常");
        }
    }

    public static byte[] string2Byte(String src) {
        return string2Byte(src, "UTF-8");
    }

    public static byte[] string2Byte(String src, String charset) {
        Object var2 = null;

        try {
            if (src == null) {
                src = "";
            }

            if (StringUtils.isBlank(charset)) {
                charset = "UTF-8";
            }

            byte[] res = src.getBytes(charset);
            return res;
        } catch (Exception var4) {
            log.info(var4.getMessage(), var4);
            throw new RuntimeException("字符串转byte数组异常");
        }
    }

}
